package edu.utdallas_elearn_calendar.utdallas_elearn_calendar_app;

import android.app.Activity; 
import android.content.Context; 
//import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.EditText; 
import android.content.SharedPreferences; 
//import android.widget.Toast;

public class AskUserPass extends Activity { 
	private SharedPreferences prefs;
	private EditText mUserNameText;
	private EditText mPasswordText;
	private EditText mLinkText;

	public void onCreate(Bundle savedInstanceState) { 
		super.onCreate(savedInstanceState); 
        setContentView(R.layout.ask_user_pass);  

        prefs = new ObscuredSharedPreferences(  
        	    this, this.getSharedPreferences("preferences", Context.MODE_PRIVATE) );
        mUserNameText = (EditText) findViewById(R.id.txtUserName);
        mPasswordText = (EditText) findViewById(R.id.txtPassword);
        mLinkText = (EditText) findViewById(R.id.txtLink);
        populateFields();
    } 


	private void populateFields() {
		String username = "";
		String password = "";
		String elearningLink = "";
		
		username = prefs.getString("UserName", "");
		password = prefs.getString("PassWord", "");
		elearningLink = prefs.getString("ElearningLink", ""); 
/*		
		Toast.makeText(this, "The username = " + username + ".", Toast.LENGTH_LONG).show();
		Toast.makeText(this, "The password = " + password + ".", Toast.LENGTH_LONG).show();
		Toast.makeText(this, "The elearning link = " + elearningLink + ".", Toast.LENGTH_LONG).show();
*/		
		mUserNameText.setText(username);
		mPasswordText.setText(password);
		mLinkText.setText(elearningLink);
	}

	protected void onStart() { 
        super.onStart(); 
        // The activity is about to become visible. 
	} 

    protected void onResume() { 
        super.onResume(); 
        // The activity has become visible (it is now "resumed"). 
    } 

    protected void onPause() { 
    	super.onPause(); 
        // Another activity is taking focus (this activity is about to be "paused"). 
    } 

    protected void onStop() { 
        super.onStop(); 
        // The activity is no longer visible (it is now "stopped") 
    } 

    protected void onDestroy() { 
        super.onDestroy(); 
        // The activity is about to be destroyed. 
    }

    public void okBtnClicked(View view) { 
        switch (view.getId()) { 
        case R.id.btnOK: 
	        EditText login = (EditText) findViewById(R.id.txtUserName); 
	        String username = login.getText().toString(); 
	        EditText pass = (EditText) findViewById(R.id.txtPassword); 
	        String password = pass.getText().toString(); 	  
	        EditText link = (EditText) findViewById(R.id.txtLink);
	        String elink = link.getText().toString();
	        
	        //Add UserName and PassWord to the preferences file 
	        prefs.edit().putString("UserName", username).commit(); 
	        prefs.edit().putString("PassWord", password).commit(); 
	        prefs.edit().putString("ElearningLink", elink).commit();
	        
	        finish();
	        //Intent done = new Intent(view.getContext(), events.class); 
	        //startActivity(done); 
	        //break; 
		} 
    }
}